/***************************************************************************
*   Copyright (C) 2006 by Yuri Ovcharenko                                 *
*   amwsoft@gmail.com                                                     *
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU General Public License as published by  *
*   the Free Software Foundation; either version 2 of the License, or     *
*   (at your option) any later version.                                   *
*                                                                         *
*   This program is distributed in the hope that it will be useful,       *
*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
*   GNU General Public License for more details.                          *
*                                                                         *
*   You should have received a copy of the GNU General Public License     *
*   along with this program; if not, write to the                         *
*   Free Software Foundation, Inc.,                                       *
*   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
***************************************************************************/
#include "serialsettings.h"

#include <QtGui>

SerialSettings::SerialSettings( QWidget *parent )
    : QDialog( parent )
{
  QVBoxLayout *lv;
  QHBoxLayout *lh;
  QGridLayout *lg;
  QSpacerItem *sp;
  QPushButton *b;

  lv = new QVBoxLayout(this);

  lg = new QGridLayout();
  lv->addLayout(lg);

  lg->addWidget(new QLabel(tr("Port name: ")), 0, 0);
  lePort = new QLineEdit();
  lg->addWidget(lePort, 0, 1);

  lg->addWidget(new QLabel(tr("Baudrate: ")), 1, 0);
  cbBaud = new QComboBox();
  cbBaud->addItem("9600", 9600);
  cbBaud->addItem("19200", 19200);
  cbBaud->addItem("38400", 38400);
  cbBaud->addItem("57600", 57600);
  cbBaud->addItem("115200", 115200);
  cbBaud->addItem("230400", 230400);
  cbBaud->addItem("460800", 460800);
  cbBaud->addItem("921600", 921600);
  lg->addWidget(cbBaud, 1, 1);

  lh = new QHBoxLayout();
  lv->addLayout(lh);
  sp = new QSpacerItem(10, 1, QSizePolicy::Expanding, QSizePolicy::Fixed);
  lh->addItem(sp);

  b = new QPushButton(tr("OK"));
  connect(b, SIGNAL(clicked()), this, SLOT(accept()));
  lh->addWidget(b);

  b = new QPushButton(tr("Cancel"));
  connect(b, SIGNAL(clicked()), this, SLOT(reject()));
  lh->addWidget(b);
}

SerialSettings::~SerialSettings()
{
}

void SerialSettings::settings(QString & port, int & baud)
{
  port = lePort->text();
  baud = cbBaud->itemData(cbBaud->currentIndex()).toInt();
}

void SerialSettings::setSettings(const QString & port, const int baud)
{
  lePort->setText(port);
  for (int i = 0; i < cbBaud->count(); i++)
  {
    if (cbBaud->itemData(i).toInt() == baud )
    {
      cbBaud->setCurrentIndex(i);
      return;
    }
  }
}

/* End of file */
